<?php
class Payment_model extends CI_Model 
{
	
    
    var $payment_id;
    var $table_name              = 'payment';
	var $fields                  = array('user_id','payment_amount','bank','branch','account_no','challan_no','remarks');
	var $required_fields         = array('user_id','payment_amount');

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
		
    }
	 function getPayments($start = 0, $limit = 10,$like,$where = array())
	 {
    	$this->db->order_by('payment.updated DESC');
    	$this->db->where($where);
		$this->db->join('users','users.id=payment.user_id');
		if(!empty($like))
		{
			$this->db->like($like);
		}
    	$query                        = $this->db->get($this->table_name,$limit,$start);
		$records                      = $query->result_array();

		$this->db->select('count(id) as total');
    	$this->db->where($where);
		if(!empty($like))
		{
			$this->db->like($like);
		}
    	$rst                           = $this->db->get($this->table_name);
		$total                         = $rst->first_row()->total;
		
		$obj->records                  = $records;
		$obj->total                    = $total;
		return $obj;
    }
	
	function required($data = array()) 
	{
    	if(empty($data)) return false;
    	$this->obj = get_instance();
    	$status                 = $this->obj->retrieve->required($this->required_fields, $data);
    	return $status;
    }
    
	function add($data = array())
	{
    	if(empty($data)) return -1;
    	if($this->required($data) ) {
    		$status = $this->db->insert($this->table_name, $data);
			$this->payment_id           = $this->db->insert_id();
			return 1;
    	} else {
    		return -2;
    	}
    }
	
	function udpate($id = '', $data = array(), $hash ='')
	{
    	if(empty($data) || empty($id)) return -1;

    	if($this->required($data)) 
		{
    		$this->db->where(array('id' => $id));
			$status = $this->db->update($this->table_name, $data);
			return $status;
    	} 
		else 
		{
    		return -2;
    	}
    }
    
	function delete($id = '')
	{
		if(empty($id)) return -1;
		$data['deleted']               = 1;
		$this->db->where(array('id' => $id));
		$status                        = $this->db->update($this->table_name, $data);
		return $status;
    }
	function getEntries()
	{
		$where['deleted']=0;
		$this->db->where($where);
        $query = $this->db->get('courses');
        return $query->result();
				
    

	}

  

}

?>